/*
Copyright 2011 Raymond Giorgi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package edu.pitt.cs3530.configuration;

import java.util.List;

import edu.pitt.cs3530.configuration.FrontEndConfigrationHandler.ConfigurationObject;
import edu.pitt.cs3530.configuration.FrontEndConfigrationHandler.ControllerConfiguration;
import edu.pitt.cs3530.configuration.FrontEndConfigrationHandler.PredictorConfiguration;
import edu.pitt.cs3530.configuration.FrontEndConfigrationHandler.QosConfiguration;
import edu.pitt.cs3530.configuration.FrontEndConfigrationHandler.ReactorConfiguration;

public class FrontEndConfiguration {

	private int connectingPort;
	private int utilizationToKeep;
	private long predictorSleepTime;
	private long reactorSleepTime;
	private long timeToKeepRequests;
	private long lateDeadline;
	private long earlyDeadline;
	private double earlyThreshhold;
	private double lateThresshold;
	private int predictorIntervals;
	private double utilizationUpperBound;
	private double utilizationLowerBound;
	private double frequencyScaleFactor;
	private String frontEndHostName;
	private String temporaryDirectory;
	private long timeToOn;
	private long timeToOff;
	private long timeToScale;
	private long predictionLength;
	private String wakePrefix;
	private String loadBalancerFactoryDirectory;
	private long reactiveScaleDownTime;
	private double predictorUpperUtilization;
	private double predictorLowerScaleUtilization;
	private double predictorLowerOffUtilization;
	private List<ControllerConfiguration> controllerConfigurations;
	private List<PredictorConfiguration> predictorConfigurations;
	private List<ReactorConfiguration> reactorConfigurations;
	private List<QosConfiguration> qosConfigurations;

	private FrontEndConfiguration() {
	}

	public double getPredictorUpperUtilization() {
		return predictorUpperUtilization;
	}

	public double getPredictorLowerScaleUtilization() {
		return predictorLowerScaleUtilization;
	}

	public double getPredictorLowerOffUtilization() {
		return predictorLowerOffUtilization;
	}

	public long getReactiveScaleDownTime() {
		return reactiveScaleDownTime;
	}

	public int getConnectingPort() {
		return connectingPort;
	}

	public int getUtilizationToKeep() {
		return utilizationToKeep;
	}

	public long getPredictorSleepTime() {
		return predictorSleepTime;
	}

	public long getReactorSleepTime() {
		return reactorSleepTime;
	}

	public long getTimeToKeepRequests() {
		return timeToKeepRequests;
	}

	public long getLateDeadline() {
		return lateDeadline;
	}

	public long getEarlyDeadling() {
		return earlyDeadline;
	}

	public double getEarlyThresshold() {
		return earlyThreshhold;
	}

	public double getLateThresshold() {
		return lateThresshold;
	}

	public int getPredictorIntervals() {
		return predictorIntervals;
	}

	public double getUtilizationUpperBound() {
		return utilizationUpperBound;
	}

	public double getUtilizationLowerBound() {
		return utilizationLowerBound;
	}

	public double getFrequencyScaleFactor() {
		return frequencyScaleFactor;
	}

	public String getFrontEndHostName() {
		return frontEndHostName;
	}

	public String getTemporaryDirectory() {
		return temporaryDirectory;
	}

	public long getTimeToOff() {
		return timeToOff;
	}

	public long getTimeToOn() {
		return timeToOn;
	}

	public long getTimeToScale() {
		return timeToScale;
	}

	public long getPredictionLength() {
		return predictionLength;
	}

	public String getWakePrefix() {
		return wakePrefix;
	}

	public String getLoadBalancerFactoryDirectory() {
		return loadBalancerFactoryDirectory;
	}
	
	public List<ControllerConfiguration> getControllerConfigurations() {
		return controllerConfigurations;
	}
	
	public List<PredictorConfiguration> getPredictorConfiguration() {
		return predictorConfigurations;
	}
	
	public List<ReactorConfiguration> getReactorConfiguration() {
		return reactorConfigurations;
	}
	
	public List<QosConfiguration> getQosConfigurations() {
		return qosConfigurations;
	}

	private static FrontEndConfiguration instance = null;

	public static void Initialize(ConfigurationObject co) {
		instance = new FrontEndConfiguration();
		instance.connectingPort = co.getConnectingPort();
		instance.timeToKeepRequests = co.getTimeToKeepRequests();
		instance.utilizationLowerBound = co.getUtilizationLowerBound();
		instance.utilizationToKeep = co.getUtilizationToKeep();
		instance.utilizationUpperBound = co.getUtilizationUpperBound();
		instance.frequencyScaleFactor = co.getFrequencyScaleFactor();
		instance.frontEndHostName = co.getFrontEndHostName();
		instance.temporaryDirectory = co.getTemporaryDirectory();
		instance.wakePrefix = co.getWakePrefix();
		instance.loadBalancerFactoryDirectory = co
				.getLoadBalancerFactoryDirectory();
		instance.reactiveScaleDownTime = co.getReactiveScaleDownTime();
		instance.controllerConfigurations = co.getControllerConfigurations();
		instance.predictorConfigurations = co.getPredictorConfigurations();
		instance.reactorConfigurations = co.getReactorConfigurations();
		instance.qosConfigurations = co.getQosConfiguration();
	}

	public static FrontEndConfiguration getInstance() {
		return instance;
	}
}
